object CurryingFunction {
  def main(args: Array[String]): Unit = {
//  println(modN(10,20))
//  println(f1(10,20))
//    println(f2(30))
//    println(f3(10))
//    println(f4(20))

    val nums = List(1,2,3,4,5,6,7,8)
    println(filter(nums,modN(2)))
    println(filter(nums,modN(3)))



  }
//  def modN1(n:Int,x:Int):Boolean = ((x % n) == 0)
//  //currying定义函数
  def modN(n:Int)(x:Int):Boolean = ((x % n) == 0)
//  //4种形式的变换
//  def fN1(n:Int,x:Int) = modN1(n,x)
//  def f1(n:Int,x:Int) = modN(n)(x)
//  def f2(x:Int) = modN(10)(x)
//  def f3(n:Int) = modN(n)(10)
//  def f4 = modN(10)(_)

  def filter(xs:List[Int],p:Int => Boolean):List[Int] =
    if (xs.isEmpty) xs
    else if (p(xs.head)) xs.head :: filter(xs.tail,p)
    else filter(xs.tail,p)


}
